package org.yn.user.controller;

import org.yn.user.service.IWxuserService;
import org.yn.user.domain.Wxuser;
import org.yn.user.query.WxuserQuery;
import org.yn.base.util.AjaxResult;
import org.yn.base.util.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.yn.auth.annotation.PermissionAnnotation;
import java.util.List;

@PermissionAnnotation(name="wxuser管理",descs = "wxuser管理")
@Api("wxuser管理接口")
@RestController
@RequestMapping("/wxuser")
public class WxuserController {
    @Autowired
    public IWxuserService wxuserService;


    /**
     * 保存和修改公用的
     * @param wxuser 传递的实体
     * @return Ajaxresult转换结果
     */
    @PermissionAnnotation(name = "保存和修改Wxuser", descs = "保存和修改Wxuser")
    @ApiOperation(value = "保存和修改")
    @PostMapping
    public AjaxResult updateOrInsert(@RequestBody Wxuser wxuser) {
        if ( wxuser.getId() != null)
            wxuserService.update(wxuser);
            else
            wxuserService.insert(wxuser);
        return AjaxResult.success();
    }

    /**
    * 删除对象信息
    * @param id
    * @return
    */
    @PermissionAnnotation(name = "删除Wxuser", descs = "删除Wxuser")
    @ApiOperation(value = "删除")
    @DeleteMapping(value = "/{id}")
    public AjaxResult delete(@PathVariable("id") Long id) {
            wxuserService.delete(id);
        return AjaxResult.success();
    }

    //获取用户
    @PermissionAnnotation(name = "获取单个Wxuser", descs = "获取单个Wxuser")
    @ApiOperation(value = "获取单个Wxuser")
    @GetMapping("/{id}")
    public AjaxResult selectById(@PathVariable("id") Long id) {
        Wxuser wxuser =wxuserService.selectById(id);
        return AjaxResult.success(wxuser);
    }


    /**
    * 查看所有的XX信息
    * @return
    */
    @PermissionAnnotation(name = "获取所有Wxuser", descs = "获取所有Wxuser")
    @ApiOperation(value = "获取所有Wxuser")
    @GetMapping
    public AjaxResult selectAll() {

        List< Wxuser> list = wxuserService.selectAll();
        return AjaxResult.success(list);
    }


    /**
    * 分页查询数据
    *
    * @param query 查询对象
    * @return PageInfo 分页对象
    */
    @PermissionAnnotation(name = "分页查询Wxuser", descs = "分页查询Wxuser")
    @ApiOperation(value = "分页查询Wxuser")
    @PutMapping
    public AjaxResult queryPage(@RequestBody WxuserQuery query) {
        PageInfo<Wxuser> pageInfo = wxuserService.queryPage(query);
        return AjaxResult.success(pageInfo);
    }

    /**
     * 批量删除
     * @param ids
     * @return
     */
    @PermissionAnnotation(name = "批量删除Wxuser", descs = "批量删除Wxuser")
    @ApiOperation(value = "批量删除Wxuser")
    @PatchMapping
    public AjaxResult batchDelete(@RequestBody List<Long> ids) {
            wxuserService.batchDelete(ids);
        return AjaxResult.success();
    }
}